
#ifndef __DS1307_H_
#define __DS1307_H_

#include "driver/i2c.h"

typedef struct 
{
    union {
        uint8_t value;
        struct 
        {
            uint8_t seconds :4;
            uint8_t ten_sec :3;
            uint8_t ch :1;
        };
        
    };
}second_data_TypeDef;

typedef struct 
{
    union {
        uint8_t value;
        struct 
        {
            uint8_t minutes :4;
            uint8_t ten_min :3;
            uint8_t bit7 :1;
        };
        
    };
}minutes_data_TypeDef;

typedef struct 
{
    union {
        uint8_t value;
        struct 
        {
            uint8_t hours :4;
            uint8_t ten_hour :2;
            uint8_t jinzhi :1;
            uint8_t :1;
        };
        
    };
}hours_data_TypeDef;

typedef struct 
{
    union {
        uint8_t value;
        struct 
        {
            uint8_t week :3;
            uint8_t :5;
        };
        
    };
}weeks_data_TypeDef;

typedef struct 
{
    union {
        uint8_t value;
        struct 
        {
            uint8_t date :4;
            uint8_t ten_date:2;
            uint8_t :2;
        };
        
    };
}dates_data_TypeDef;


typedef struct 
{
    union {
        uint8_t value;
        struct 
        {
            uint8_t month :4;
            uint8_t ten_month:1;
            uint8_t :3;
        };
        
    };
}months_data_TypeDef;

typedef struct 
{
    union {
        uint8_t value;
        struct 
        {
            uint8_t year :4;
            uint8_t ten_year:4;
        };
    };
}years_data_TypeDef;


typedef struct 
{
    second_data_TypeDef seconds;
    minutes_data_TypeDef minutes;
    hours_data_TypeDef hours;
    weeks_data_TypeDef weeks;
    dates_data_TypeDef dates;
    months_data_TypeDef months;
    years_data_TypeDef years;
}Rtc_time_typedef;


#define DS1307_I2C_CHANNEL  I2C_NUM_0
#define DS1307_MASTER_SCL_IO  (19)
#define DS1307_MASTER_SDA_IO  (18)
#define DS1307_FREQ_HZ   (100000) // default setting 100Hhz
#define DS1307_ADDR 0x68   //7 bit address
esp_err_t ds1307_set_time(uint8_t year,uint8_t month,uint8_t date,uint8_t week,uint8_t hour ,uint8_t minute,uint8_t second);
esp_err_t ds1307_i2c_master_init(void);
esp_err_t ds1307_read_data( uint8_t * data,uint8_t size);
#endif
